﻿/// <reference path="../../jquery/jquery-1.3.2-vsdoc.js" />
/// <reference path="../Complaint.Namespaces.js" />
/// <reference path="../Complaint.Common.js" />

var settlementTypeId;

$(function() {
    $("#addDialog").dialog(
            {
                autoOpen: false,
                bgiframe: true,
                modal: true,
                width: 400,
                buttons:
                {
                    "Cancel": function() {
                        $(this).dialog("close");
                    },
                    "OK": function() {
                        save();
                        $(this).dialog("close");
                    }
                }
            });

    $("#add").click(function(evt) {
        settlementTypeId = 0;
        $("#addDialog").load(Complaint.Common.AdminRoot + "/SettlementType/Add", null,
                    function() {
                        $("#addDialog").dialog("open");
                    });
    });
});

function save() {
    if (settlementTypeId == 0)
        $.post(
                    Complaint.Common.AdminRoot + "/SettlementType/Add",
                    {
                        Type: $("#Type").attr("value"),
                        Description: $("#Description").attr("value")
                    },
                    function(data) {
                        $("#grid").html(data);
                    }
                )
    else
        $.post(
                    Complaint.Common.AdminRoot + "/SettlementType/Edit",
                    {
                        SettlementTypeID: settlementTypeId,
                        Type: $("#Type").attr("value"),
                        Description: $("#Description").attr("value")
                    },
                    function(data) {
                        $("#grid").html(data);
                    }
                )
}

function animateMessage() {
    $("#msg").text("Successfully deleted.");
    $("#msg").animate({ fontSize: "1.5em" }, 400);
    $("#msg").fadeOut("slow");
}

function edit() {
    settlementTypeId = arguments[0];
    $("#addDialog").load(
            Complaint.Common.AdminRoot + "/SettlementType/Edit/" + arguments[0],
            null,
            function() {
                $("#addDialog").dialog("open");
            });
}